<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * @author Меркулов Илья aka Bit0reZ
 * @license GNU GPLv3
 */

class Welcome extends CI_Controller {
	
	var $env = ENVIRONMENT;
	var $role;
	var $uid;
	var $base_url;
	var $stat;
	var $bbb_url;
	var $salt;
	var $benchmark = true;

	function __construct()
	{
		parent::__construct();
                $this->load->config('eclass_cfg');
                $this->load->helper('data');
                $this->load->helper('url');
                $this->load->helper('date');
                $this->load->database('default');
                $this->load->model('WebinarDB','wdb');
                $this->load->library('parser');
                $this->load->library('session');
                $this->load->library('BigBlueButton', NULL, 'bbb');
                $this->load->library('table');
                $this->load->library('Webinar');
		$this->load->model('Check', 'check');
		
		$this->uid = $this->session->userdata('UID');
                $this->role = $this->session->userdata('role');
                $this->base_url = base_url();
		$this->bbb_url = $this->config->item('bbb_url');
		$this->salt = $this->config->item('salt');
	}

	function index()
	{
                //$this->output->enable_profiler(false);
                if($this->env == 'development') $this->output->enable_profiler($this->benchmark);
                $dt['base_url'] = @$data['base_url'] = base_url();
                $data['url'] = $this->config->item('bbb_url');
                $data['salt'] = $this->config->item('salt');
                $data['UID'] = $UID = @$this->uid;//$this->session->userdata('UID');
                $data['role'] = @$this->role;// = $this->session->userdata('role');
                $data['surname'] = $this->session->userdata('surname');
                $data['firstname'] = $this->session->userdata('firstname');
                $data['secondname'] = $this->session->userdata('secondname');

		$warning_message['warning'] = $this->wdb->warning();
		$data['warning'] = $this->parser->parse("templates/warning.html", $warning_message, TRUE);
		unset($warning_message['warning']);
                $dt['header'] = $this->parser->parse("templates/header.html", $data, TRUE);
		unset($data['warning']);

                $dt['about'] = $this->parser->parse('templates/about.html', $data, true);
                //Now Running
                //$data['webinar'] = $this->webinar->now_running($data['url'], $data['salt']);
		//$data['webinar'] = array(); $data['message'] = array();
		//if(!$data['webinar']) $data['message'][0] = array('text' => "На данный момент вебинаров не проводится.");
		//else $data += array('message' => array()); // TODO: Fix IT!

                //$dt['nowRunning'] = $this->parser->parse('templates/nowRunning.html', $data, true);
                //unset($data['webinar']);
                //End Now Running
                $dt['footer'] = $this->parser->parse('templates/footer.html', $data, true);

                if($UID == FALSE )//|| $UID < 1)
                {
                        $dt['account'] = $this->parser->parse('templates/login.html', $data, true);
                        //$dt['welcome'] = $this->parser->parse('templates/welcome.html', $data, true);
                }
                else
                {
                        $dt['account'] = $this->parser->parse('templates/uInfo.html', $data, true);
                        //$dt['welcome'] = $this->parser->parse('templates/'.$this->role.'.html', $data, true);
                }

                $data['week'] = array(
                    array('dayOfWeek' => 'Пн'),
                    array('dayOfWeek' => 'Вт'),
                    array('dayOfWeek' => 'Ср'),
                    array('dayOfWeek' => 'Чт'),
                    array('dayOfWeek' => 'Пт'),
                    array('dayOfWeek' => 'Сб'),
                    array('dayOfWeek' => 'Вс'));
                //$data['calendar'] = $this->wdb->calendarMonth(mdate('%m',now()),mdate('%Y',now()));
                $data['wtf'] = 'planned';
                $dt['calendar'] = $this->parser->parse('templates/calendar.html', $data, true);
		unset($data['wtf']);
		unset($data['week']);
		($this->env == 'production')? $dt['metrica'] = $this->parser->parse('templates/metrica.html', $data, true) : $dt['metrica'] = '';
                $this->parser->parse('templates/new.html', $dt);
	}
	
	function menu($tpl)
	{
		$dt['base_url'] = @$data['base_url'] = base_url();
                $data['url'] = $this->config->item('bbb_url');
                $data['salt'] = $this->config->item('salt');
                $data['UID'] = $UID = @$this->uid;//session->userdata('UID');
                $data['role'] = $role = @$this->role;//session->userdata('role');
                $data['surname'] = $this->session->userdata('surname');
                $data['firstname'] = $this->session->userdata('firstname');
                $data['secondname'] = $this->session->userdata('secondname');

		$warning_message['warning'] = $this->wdb->warning();
		$data['warning'] = $this->parser->parse("templates/warning.html", $warning_message, TRUE);
		unset($warning_message['warning']);
		unset($warning_message);
		
                $dt['header'] = $this->parser->parse("templates/header.html", $data, TRUE);
		unset($data['warning']);

		if($UID == FALSE || $UID < 1)
                {
                        $dt['account'] = $this->parser->parse('templates/login.html', $data, true);
                }
                else
                {
                        $dt['account'] = $this->parser->parse('templates/uInfo.html', $data, true);
                }
		
		if($tpl == 'feedback') $data['types'] = $this->wdb->types();
		else $data['types'] = '';
                $dt['content'] = $this->parser->parse('templates/'.$tpl.'.html', $data, true);
		unset($data['types']);
                
		$data['uri'] = $tpl;
                $dt['menu'] = $this->parser->parse('templates/menu.html', $data, true);
		unset($data['uri']);
		
		($this->env == 'production')? $dt['metrica'] = $this->parser->parse('templates/metrica.html', $data, true) : $dt['metrica'] = '';
		$dt['footer'] = $this->parser->parse('templates/footer.html', $data, true);
		$this->parser->parse('templates/menu_tpl.html', $dt);
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
